package com.xcity.pomelo.response;

import com.xcity.db.entity.Guild;
import com.xcity.db.entity.GuildMember;
import com.xcity.db.entity.Player;
import com.xcity.game.guild.GuildService;
import com.xcity.game.player.PlayerUtils;

import naga.x.App;

public abstract class AbstractViewPlayerResponse extends Response {

	public long id;
	public String name;
	public String icon;
	public byte sex;
	public int level;
	public int vipLvl;
	public int exp, maxExp;
	public int str, maxStr;
	public int vigour, maxVigour;
	public long gold;
	public long fixAssets;
	public int stone;
	public String gname;
	
	public AbstractViewPlayerResponse(int serial, Player player) {
		super(serial);
		this.id = player.getId();
		this.name = player.getName();
		this.icon = player.getIcon();
		this.sex = player.getSex();
		this.level = player.getLevel();
		this.vipLvl = player.getVipLvl();
		this.exp = (int) player.getExp();//PlayerUtils.getExpOfNowLvl(player.getExp());
		this.maxExp = PlayerUtils.getExpCalc().getExp(player.getLevel() + 1);//PlayerUtils.getNextLvlNeedExp(player.getLevel());
		this.str = player.getStrength();
		this.maxStr = PlayerUtils.getMaxStrength(player);
		this.vigour = player.getVigour();
		this.maxVigour = PlayerUtils.getMaxVigour(player);
		this.gold = player.getGold();
		this.fixAssets = player.getFixedAssets();
		this.stone = player.getStone();

		GuildService gs = App.getApp().getServiceManager().get(GuildService.class);
		GuildMember member = gs.getGuildMember(player.getId());
		if(member == null){
			member = gs.loadGuildMember(player.getId());
		}
		if(member != null){
			if(member.getGuildid() > 0){
				Guild guild = gs.findGuildById(member.getGuildid());
				if(guild != null){
					this.gname = guild.getName();
				}
			}
		}
	}

}
